//线索池表单表格
var $cluePoolTable = $('#cluePoolTableList');
var abs = new verjs_select();
//防止表头与表格不对齐
$(window).resize(function () {
    $cluePoolTable.bootstrapTable('resetView');
});
$(function () {
    $('#search').css('display', 'none');
    // 创建时间
    $('.date-input').datepicker({
        language: "zh-CN",
        autoclose: true,
        clearBtn: true,
        todayHighlight: true,
        format: "yyyy-mm-dd"
    });
    //有效时间
    $('#effectiveTime').datepicker({
        language: "zh-CN",
        autoClose: true,
        clearBtn: true,
        todayHighlight: true,
        format: "yyyy-mm-dd"
    });

    //初始化公司下拉框(--搜索条件)
    loadCompanySelect();
    //初始化线索池表单
    cluePoolTableListInit();

    // 高级筛选
    $('#filterContent').on('show.bs.collapse', function () {
        $('.btn-senior').html('<i class="mdi mdi-close"></i>关闭筛选');
    }).on('hide.bs.collapse', function () {
        $('.btn-senior').html('<i class="mdi mdi-sort-variant"></i>高级筛选');
    }).on('hidden.bs.collapse', function () {
        resetCluePoolQueryParams('#filterContent');
    });


});

// 关闭弹层
function cancelModel() {
    $("#editModel").modal('hide');
}

/**
 * 加载公司下拉列表
 */
function loadCompanySelect() {
    $.getJSON("/sysCompany/selectCompanies", function (data) {
        if (data.code == '000000') {
            var optionHtml = '';
            var optionArr = data.data;
            var optionSelected = $('#companySelect option:selected').val();
            //公司搜索条件下拉框
            var searchCompanyOptionHtml = '<option value="">全部</option>';
            optionArr.map(function (item, index) {
                searchCompanyOptionHtml += '<option value="' + item.companyId + '">' + item.companyName + '</option>';
            });
            $('#searchCompanySelect').html(searchCompanyOptionHtml);
            var selectDate = [];
            for (var i = 0, len = data.data.length; i < len; i++) {
                var company = data.data[i];
                var selectCompany = {};
                selectCompany.id = company.companyId;
                selectCompany.name = company.companyName;
                selectDate.push(selectCompany);
            }
            abs.render({
                elem: "#search",
                data: selectDate,
                init_value: [1],
                body_height: 300,
                checkbox: true,
                name: "test"
            });
            $('#searchoption-list').css('z-index',1000);
            $('#searchCompanySelect').selectpicker({
                sanitize: true,
                size: 8
            });
        }
    });
}

/**
 * 全部/周/月/年切换
 * @param time
 */
function selectTime(time) {
    if (time == 'all') {//全部
        $('.all').addClass('active-second');
        $('.year').removeClass('active-second');
        $('.week').removeClass('active-second');
        $('.month').removeClass('active-second');
        $("#dateType").val("all");
    }
    if (time == 'year') {//本年
        $('.year').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.week').removeClass('active-second');
        $('.month').removeClass('active-second');
        $("#dateType").val("thisYear");
    }
    if (time == 'month') {//本月
        $('.month').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.year').removeClass('active-second');
        $('.week').removeClass('active-second');
        $("#dateType").val("thisMonth");
    }
    if (time == 'week') {//本周
        $('.week').addClass('active-second');
        $('.all').removeClass('active-second');
        $('.year').removeClass('active-second');
        $('.month').removeClass('active-second');
        $("#dateType").val("thisWeek");
    }
    $('#createTm').val('');//清空创建时间搜索条件
    $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1});
}

/**
 * 线索池表单--分页列表页
 */
function cluePoolTableListInit() {
    //先销毁表格
    $cluePoolTable.bootstrapTable('destroy');
    $cluePoolTable.bootstrapTable({
        classes: 'table table-bordered table-hover table-striped',
        url: '/cluePoolPublic/selectCluePoolList',//请求地址
        method: 'post',//请求方式
        contentType: "application/x-www-form-urlencoded",//请求内容类型
        dataType: "json",//数据类型
        striped: true,//是否显示行间隔色
        sortable: true,//是否启用排序
        sortOrder: "desc",//排序方式
        sortName: 'createTm',//排序字段
        cache: false,//是否使用缓存
        showColumns: false,//显示隐藏列
        showRefresh: false,//显示刷新按钮
        showToggle: false,//切换显示样式
        showFooter: false,//显示Table脚部
        pagination: true,//是否显示分页
        showPaginationSwitch: false,//是否显示分页按钮
        clickToSelect: false,//是否启用点击选中行
        singleSelect: false,
        minimumCountColumns: 2,//最少要显示的列数
        undefinedText: '',//cell没有值时显示
        sidePagination: "server",//分页方式：client客户端分页，server服务端分页
        uniqueId: 'poolId',
        idField: 'poolId',
        pageSize: globalPageSize,//每页的记录行数
        pageNumber: 1,//初始化加载第1页，默认第1页
        pageList: globalPageList,//可供选择的每页的行数

        fixedColumns: true,     // 冻结列
        fixedNumber: 1,         // 左侧固定列
        fixedRightNumber: 2,    // 右侧固定列

        queryParams: queryParams,//查询参数
        columns: [
            {title: '主键', field: 'poolId', visible: false},
            {title: '序号', field: 'index', align: 'left', valign: 'middle', width: '52', formatter: indexFormat},
            {title: '线索池名称' ,field: 'poolName', sortable: true, align: 'left', valign: 'middle', width: '120', class: 'ellipsis'},
            {title: '线索池类别', field: 'poolCategory', sortable: true, align: 'left', valign: 'middle',formatter: poolCategoryFormat},
            {title: '所属公司', field: 'companyName', sortable: true, align: 'left', valign: 'middle'},
            {title: '创建人', field: 'createPeopleName', sortable: true, align: 'left', valign: 'middle'},
            {title: '创建时间', field: 'createTm', sortable: true, align: 'left', valign: 'middle'},
            {title: '标签', field: 'poolTag', sortable: true, align: 'left', width: '120', valign: 'middle'},
            {title: '类型', field: 'poolType', sortable: true, align: 'left', valign: 'middle',formatter: poolTypeFormat},
            {title: '跟进统计', field: 'followStatistics', sortable: true, align: 'left', valign: 'middle'},
            {title: '使用比例', field: 'useProportion', sortable: true, align: 'left', valign: 'middle'},
            {title: '转化比例', field: 'conversionProportion', sortable: true, align: 'left', valign: 'middle'},
            {title: '操作',field: 'operateFlag',align: 'right',events: operateEvents, width: '112', formatter: genderOpt},
            {title: '是否启用',field: 'poolState', align: 'right', width: '80', formatter: poolStateFormat},
            {field: '是否是默认池子', field:"defaultMark", visible: false},
            {field: '分配方式', field:"allocation", visible: false},
            {field: '省份ID', field: 'provinceId', visible: false},
            {field: '省份名称', field: 'provinceName', visible: false},
            {field: '城市ID', field: 'cityId', visible: false},
            {field: '行业', field: 'industry', visible: false},
            {field: '公司ID', field: 'companyId', visible: false}
        ],
        responseHandler: function (result) {
            if (result.code == "000000") {
                var obj = {
                    "rows": result.data,
                    "total": result.totalRecords//总条数
                };
            } else {
                var obj = {
                    "total": 0,
                    "rows": [],
                }
            }
            return obj;
        },
        onLoadSuccess: function () {
            // table操作列下拉菜单效果
            tableNav();

            // table列可拖动宽度
            $('.JCLRgrips').remove();
            $('#cluePoolTableList').css({
                minWidth: $('#cluePoolTableList').width()
            }).colResizable({
                resizeMode: 'overflow',
                liveDrag: true,
                gripInnerHtml: "<div class='grip'></div>",
                draggingClass: "dragging",
                disabledColumns: [0, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12],      // 禁止拖动的列
                postbackSafe: true,                                         // 刷新后保持拖动的宽度
                partialRefresh: true,                                       // 刷新表格之后继续保持可拖动功能
                flush: true,
                minWidth: 80,
                /*onResize: function () {
                }*/
            });
        },
        onLoadError: function (status) {
            if (status == 403) {
                alert("权限不足！禁止访问！");
            } else {
                //加载失败时执行
                alert("加载失败！");
            }
        },
        formatLoadingMessage: function () {
            return "请稍等，加载中...";
        },
        formatNoMatches: function () {
            return '无符合条件的记录';
        },
        /*onResetView: function () {
        }*/
    });
}

/**
 * --列表序列号
 */
function indexFormat(value, row, index) {
    return index + 1;
}

/**
 * 线索池类型(优、良、一般)
 * @param value
 * @param row
 * @param index
 * @returns {string}
 */
function poolTypeFormat(value, row, index) {
    if (value == null || value == undefined) {
        return "-";
    } else if (1 == value) {
        return "优";
    } else if (2 == value) {
        return "良";
    }else if(3 == value){
        return "一般";
    }
}

/**
 * 线索池类别格式化
 * @param value
 * @param row
 * @param index
 * @returns {string}
 *
 */
function poolCategoryFormat(value, row, index){
    if (value == null || value == undefined) {
        return "-";
    } else if (1 == value) {
        return "私有池";
    } else if (2 == value) {
        return "分公司公有池";
    }else if(3 == value){
        return "全国公有池";
    }else if(0 == value){
        return "个人池";
    }
}

/**
 * 线索池停用/启用状态
 * @param value
 * @param row
 * @param index
 * @returns {string}
 */
function poolStateFormat(value, row, index){
    if(row.defaultMark == '1' && row.poolCategory == 3){//defaultMark:默认池;poolCategory:线索类别--3全国池
        return '';
    }
    if(row.operateFlag == true){
        var is_checked = '';
        if (value == null || value == undefined || value == 0) {
            return "";
        }else if (value == 2) {
            is_checked = '';
        } else if (value == 1) {
            is_checked = 'checked="checked"';
        }
        var poolStateHtml = '<label class="lyear-switch switch-solid switch-success">' +
            '<input type="checkbox" id="poolState' + row.poolId  + '" ' + is_checked + '>' +
            '<span  onClick="updatePoolState(\'' + row.poolId + '\', \'' + value + '\')"></span>' +
            '</label>';
        return poolStateHtml;
    }else{
        return '';
    }
}

/**
 * 开启/停用线索池
 * @param poolId
 * @param poolState
 */
function updatePoolState(poolId, poolState){
    var poolState = (poolState == 1) ? 2 : 1; // 发送参数值跟当前参数值相反
    var confirmMessage = '';
    if (poolState == 1) {
        confirmMessage = "确定启用吗？";
    } else {
        confirmMessage = "确定停用吗？";
    }

    $.alert({
        title: '提示',
        content: confirmMessage,
        buttons: {
            confirm: {
                text: '确认',
                btnClass: 'btn-primary',
                action: function () {
                    $.ajax({
                        type: "post",
                        url: "/cluePoolPublic/updatePoolState",
                        data: {
                            poolId: poolId,
                            poolState: poolState
                        },
                        dataType: 'json',
                        success: function (data, status) {
                            if (data.code == '000000') {
                                $cluePoolTable.bootstrapTable('updateCellById', {id: poolId, field: 'poolState', value: poolState});
                            } else {
                                $.alert(data.message);
                                $cluePoolTable.bootstrapTable('updateCellById', {id: poolId, field: 'poolState', value: poolState}); // 因开关点击后样式是变的，失败也重置下
                            }
                        },
                        error: function () {
                            $.alert('修改失败，请稍后再试!');
                            $cluePoolTable.bootstrapTable('updateCellById', {id: poolId, field: 'poolState', value: poolState}); // 因开关点击后样式是变的，失败也重置下
                        }
                    });
                }
            },
            cancel: {
                text: '取消',
                action: function () {
                    if(poolState == 1){
                        $("#poolState" + poolId).prop('checked',false);
                    }else {
                        $("#poolState" + poolId).prop('checked',true);
                    }
                }
            }
        }
    });
}

/**
 * 自定义操作列内容
 */
function genderOpt(value, row, index) {
    let html = '';
    if (row.operateFlag) {
        html += '<button class="btn btn-default" id="detail"><i class="mdi mdi-eye"></i>查看</button>';
        html += '<div class="dropdown" style="margin-right: -10px;"><button class="btn btn-link" data-index="' + index + '"><i class="mdi mdi-dots-vertical"></i></button><ul class="dropdown-menu">';
        html += '<li><a href="#!" data-toggle="modal" id="edit" data-target="#editModel">编辑</a></li>';
        html += '</ul></div>'
    } else {
        html += '<button class="btn btn-default" id="detail" style="margin-right: 15px;"><i class="mdi mdi-eye"></i>查看</button>';
    }
    return html;
}

var poolOldNature = "";

/**
 * 自定义操作列事件
 */
window.operateEvents = {
    //查看点击事件
    'click #detail': function (e, value, row, index) {
        var poolPermissionFlag = false;
        if(row.poolCategory == '1' &&  row.operateFlag == true){//线索池类别：私有池；是否可操作标识
            poolPermissionFlag = true;
        }
        parent.$(parent.document).data('multitabs').create({
            iframe : true,
            title : '线索池详情',
            url : "/front/cluePoolManager/cluePoolDetail?poolId=" + row.poolId + "&poolCategory=" + row.poolCategory + "&poolState=" + row.poolState + "&defaultMark=" + row.defaultMark + "&allocation=" + row.allocation
                  + "&companyId=" + row.companyId + "&poolPermissionFlag=" + poolPermissionFlag
        }, true);
    },
    //编辑点击事件
    'click #edit': function (e, value, row, index) {

        let cityId = row.cityId;// 市id

        let provinceId = '';        // 省id
        let provinceName = '';      // 省名称

        // 新建省市对象(不包含县)
        let newCityJson = {};
        $.each(cityJson, function (key, value) {
            if (key.length <= 8) {
                newCityJson[key] = value;
            }
        });

        // 获取市对应的省份id
        $.each(newCityJson, function (aKey, aValue) {
            $.each(aValue, function (key, value) {
                if (cityId === key) {
                    provinceId = aKey.substring(2);
                    // console.log('省份id：' + provinceId, '市id：' + cityId, '市名：' + value)
                }
            })
        });
        // 根据省份id获取省份名称
        for (let key in newCityJson[0]) {
            if (key === provinceId) {
                // console.log(newCityJson[0][key]);
                provinceName = newCityJson[0][key];
                break;
            }
        }
        getProvince(provinceId);

        $('#province').find('option[value="' + provinceId + '"]').prop('selected', true);
        $('#city').find('option[value="' + cityId + '"]').prop('selected', true);

        $.ajax({
            url: "/cluePoolPublic/selectCluePoolUpdateInfo?cluePoolId=" +row.poolId,
            async: false,
            type: "get",
            dataType: "json",
            success: function (data) {
                if (data.code == '000000') {
                    var result = data.data;
                    $("#poolId").val(row.poolId);
                    $("#cluePoolName").val(result.cluePoolName);
                    $("#source").val(result.source);
                    $("#effectiveTime").val(result.effectiveTime);
                    $("#capacity").val(result.capacity);
                    //标签回显
                    $("#tagBox").html('');
                    $("#tagBox").append('<input type="text" name="staticPath" value="" id="staticPath2"/>');
                    $("#staticPath2").val('');
                    $("#staticPath2").val(result.tag);
                    WS({
                        el: "#staticPath2",
                    });
                    var conversionMethodValue = result.conversionMethod;
                    $("input[name=conversionMethod][value= "+ conversionMethodValue + "]").prop("checked",true);
                    var nature = result.nature;
                    $("input[name=nature][value= "+ nature + "]").prop("checked",true);
                    //线索池旧性质用于更新线索池时判断删不删除公司属性
                    poolOldNature = nature;
                    //行业
                    var industry = result.industry;
                    $("#industry option[value='"+industry+"']").attr("selected","selected");
                    //线索池类型
                    var poolType = result.poolType;
                    $("#poolType option[value='"+poolType+"']").attr("selected","selected");

                }
            }
        })
    },
    //删除点击事件
    'click #delete': function (e, value, row, index) {

    },
};

/**
 * 拼接线索池表单普通查询条件参数
 */
function queryParams(params){
    params.pageSize = params.limit;
    params.pageIndex = (params.offset / params.limit) + 1;
    params.sortName = params.sort; //排序列名
    params.sortOrder = params.order;//排序方式

    params.dateType = $('#dateType').val();//dateType(all:全部; thisWeek:本周; thisMonth:本月; thisYear:本年)

    //普通搜索条件
    params.poolName = $.trim($('#poolNameMin').val());//线索池名称
    return params;
}

/**
 * 拼接线索池表单高级查询条件参数
 */
function advancedQueryParams(params){
    params.pageSize = params.limit;
    params.pageIndex = (params.offset / params.limit) + 1;
    params.sortName = params.sort; //排序列名
    params.sortOrder = params.order;//排序方式

    params.dateType = $('#dateType').val();//dateType(all:全部; thisWeek:本周; thisMonth:本月; thisYear:本年)
    //清空普通搜索条件
    $('#poolNameMin').val('');

    //高级搜索条件
    params.poolName = $.trim($('#poolName').val());//线索池名称
    params.companyId = $('#searchCompanySelect option:selected').val();//公司ID
    params.poolTag = $.trim($('#poolTag').val());//线索池标签

    //创建时间(区间)
    params.createTmStart = $('#createTmStart').val();  //创建开始日期
    params.createTmEnd = $('#createTmEnd').val();    //创建截止日期
    params.createTm = $('#createTm').val();//创建时间
    return params;
}

/**
 * 搜索点击事件
 */
var getProvinceId = '';
var getIndustry = '';
var getHotTag = '';
function searchCluePoolTableList(type,value){
    $('.all').addClass('active-second');
    $('.week').removeClass('active-second');
    $('.month').removeClass('active-second');
    $('.year').removeClass('active-second');
    $("#dateType").val("all");
    if (type === 1) {//普通条件查询
        $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: queryParams,});
        // 点击搜索重置表单并收起高级搜索 需传入高级搜索id #filterContent
        $('#filterContent').collapse('hide').on('hidden.bs.collapse', function () {
            resetCluePoolQueryParams('#filterContent');
        });
    }else if(type == 2){//高级搜索条件查询
        $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: advancedQueryParams});
    }else if(type == 3){//按地区查询
        getProvinceId = value;
        $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: function(params){
                params.pageSize = params.limit;
                params.pageIndex = (params.offset / params.limit) + 1;
                params.sortName = params.sort; //排序列名
                params.sortOrder = params.order;//排序方式
                params.provinceId = getProvinceId; //省份ID
                params.industry = getIndustry;//行业
                params.hotTag = getHotTag;//热门标签
                params.dateType = $('#dateType').val();//dateType(all:全部; thisWeek:本周; thisMonth:本月; thisYear:本年)
                return params;
            }});
    }else if(type == 4){//按行业查询
        getIndustry = value;
        $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: function(params){
                params.pageSize = params.limit;
                params.pageIndex = (params.offset / params.limit) + 1;
                params.sortName = params.sort; //排序列名
                params.sortOrder = params.order;//排序方式
                params.provinceId = getProvinceId; //省份ID
                params.industry = getIndustry;//行业
                params.hotTag = getHotTag;//热门标签
                params.dateType = $('#dateType').val();//dateType(all:全部; thisWeek:本周; thisMonth:本月; thisYear:本年)
                return params;
            }});
    }else if(type == 5){//按标签查询
        getHotTag = value;
        $cluePoolTable.bootstrapTable('refreshOptions', {pageNumber: 1, queryParams: function(params){
                params.pageSize = params.limit;
                params.pageIndex = (params.offset / params.limit) + 1;
                params.sortName = params.sort; //排序列名
                params.sortOrder = params.order;//排序方式
                params.provinceId = getProvinceId; //省份ID
                params.industry = getIndustry;//行业
                params.hotTag = getHotTag;//热门标签
                params.dateType = $('#dateType').val();//dateType(all:全部; thisWeek:本周; thisMonth:本月; thisYear:本年)
                return params;
            }});
    }

    // 地区、行业、热门条件点击切换背景
    $('.selector-box').on('click', 'a', function () {
        $(this).parents('dl').find('a').removeClass('active');
        $(this).addClass('active');
    });
}

/**
 * 重置线索池清单查询条件
 */
function resetCluePoolQueryParams(_this){
    let searchForm = '';
    if($(_this).parents('#filterContent').context == document) {
        searchForm = $(_this);
    } else {
        searchForm = $(_this).parents('#filterContent');
    }

    searchForm.find('input[type="text"]').val('');
    searchForm.find('select').find('option:first').prop('selected', 'selected');
    // 刷新下拉菜单selectpicker控件
    searchForm.find('select').selectpicker('refresh');

    // 点击重置按钮时，刷线table内容
    if($(_this).parents('#filterContent').context !== document) {
        cluePoolTableListInit();
    }
}

/**
 * 修改线索池
 */
function saveUpdatePool(){

    //线索池id
    var cluePoolId = $.trim($("#poolId").val());

    //线索池名称
    var cluePoolName = $.trim($("#cluePoolName").val());

    //省份id
    var provinceId = $('#province').val();

    //省份名称
    var provinceName = $("#province").find("option:selected").text();

    //城市id
    var cityId = $('#city').val();

    //城市名称
    var cityName = $("#city").find("option:selected").text();

    //行业
    var industry =  $("#industry").val();

    //来源
    var source = $("#source").val();

    //是否永久有效
    var permanent="";
    if( $('#yongJiu').is(':checked') ){
        permanent = 1;
    }else {
        permanent = 0;
    }

    //有效时间
    var effectiveTime = $('#effectiveTime').val();

    //容量
    var capacity = $("#capacity").val();

    //性质
    var nature = $("input[name='nature']:checked").val();

    //转换方式
    var conversionMethod = $("input[name='conversionMethod']:checked").val();

    var tagStr = $('.fm-button').text().split(' ').join(',');
    var tagStrNew = tagStr.substring(0, tagStr.lastIndexOf(','))+ tagStr.substring(tagStr.lastIndexOf(',')+1);
    //线索池标签
    var tag = tagStrNew;

    //线索池类型
    var poolType = $('#poolType').val();

    //公司id
    var selectCompany = [];
    selectCompany = abs.get_value('search');
    var companyIdList = [];
    for(let i=0;i<selectCompany.length;i++) {
        companyIdList.push(selectCompany[i].id);
    }

    //线索池名称为空和长度验证
    if (!cluePoolName) {
        promptInfo("线索池名称不能为空!");
        return;
    } else {
        if (cluePoolName.length > 20) {
            promptInfo("线索池名称长度不能大于20个字！");
            return;
        }
    }

    //所在行业
    if (!industry) {
        promptInfo("所在行业不能为空!");
        return;
    }

    //有效时间判断
    if(permanent==0&&$.trim(effectiveTime)==""){
        promptInfo("请选择有效时间！");
        return;
    }

    //标签为空判断
    if(!tag){
        promptInfo("标签不能为空！");
        return;
    }

    //线索池容量判断
    if(!capacity){
        promptInfo("线索池容量不能为空！");
        return;
    }

    //线索池性质
    if(!nature){
        promptInfo("线索池性质必选！");
        return;
    }

    var jsonData = {
        "cluePoolId":cluePoolId,
        "cluePoolName":cluePoolName,
        "provinceId":provinceId,
        "provinceName":provinceName,
        "cityId":cityId,
        "cityName":cityName,
        "industry":industry,
        "source":source,
        "permanent":permanent,
        "effectiveTime": effectiveTime,
        "capacity":capacity,
        "nature":nature,
        "conversionMethod":conversionMethod,
        "tag":tag,
        "poolType":poolType,
        "companyIdList":companyIdList,
        "oldNature":poolOldNature
    };

    $.ajax({
        url: '/cluePoolPublic/updateCluePoolPublic',
        type: 'POST',
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(jsonData),
        success: (function (data) {
            if (data.code == "000000") {
                $.alert({
                    title: '提示',
                    content: '修改成功！',
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'btn-primary',
                            action: function () {
                                //模态框关闭
                                $('#editModel').modal('hide');
                                $cluePoolTable.bootstrapTable('refresh')
                            }
                        }
                    }
                });
            } else if(data.code == "C00010"){
                $.alert("线索池名称重复！");
            } else {
                $.alert("保存失败！");
            }
        }),
        error: (function (res) {
            $.alert("保存失败！");
        })
    });
}

// 有效时间
function yongjiu() {
    if ($('#yongJiu').prop('checked') == true) {
        $("#effectiveTime").prop('disabled', true);
        $("#effectiveTime").val("");
    } else {
        $("#effectiveTime").prop('disabled', false);
    }
}

// 切换分配方式
function changeWay(type) {
    if (type == 1) {
        $('.three').css('display', 'none');
        $('.one').css('display', 'block');
    }
    if (type == 2) {
        $('.one').css('display', 'none');
        $('.three').css('display', 'block');
    }
}

// 池子
function seleceChi(type) {
    if (type == 2 ) {
        $('#search').css('display', 'inline-block')
    } else {
        $('#search').css('display', 'none')
    }
}

/**
 * 新增线索池
 */
function addCluePool(){
    parent.$(parent.document).data('multitabs').create({
        iframe : true,
        title : '创建线索池',
        url : "/front/cluePoolManager/addCluePool"
    }, true);
}

function promptInfo(content) {
    $.alert({
        title: '温馨提示',
        content: content,
        buttons: {
            confirm: {
                text: '确认',
                btnClass: 'btn-primary'
            }
        }
    });
}

/**
 * 弹窗城市选择
 * */
// 渲染城市列表
function getProvince(id) {
    let provinceNames = [];
    $.each(cityJson[0], function (key, value) {
        provinceNames.push('<option value="' + key + '">' + value + '</option>')
    });
    $('#province').html(provinceNames.join(''));
    getCity(id)
}

// 根据省获取市
function getCity(provinceId) {
    $('#city').html('');
    let key = '0,' + provinceId;
    let cityNames = [];
    $.each(cityJson[key], function (key, value) {
        cityNames.push('<option value="' + key + '">' + value + '</option>')
    });
    $('#city').html(cityNames.join(''));

}

// '切换城市'
function changeCity() {
    getCity($('#province').val());
}
